#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int, int> PII;

int n, ans;

void merge(vector<PII> &segs) {
	int ed = -2e9;
	for (auto item : segs) {
		if (ed < item.first) ans ++, ed = item.second;
		else ed = max(ed, item.second);
	}
}

int main() {
	cin >> n;
	vector<PII> segs;
	for (int i = 0; i < n; i ++) {
		int l, r;
		cin >> l >> r;
		segs.push_back({l, r});
	}
    
    sort(segs.begin(), segs.end());	
	merge(segs);
	
	cout << ans << endl;
	
	return 0;
}